package common;

import java.lang.RuntimeException;

public class JavaPrimitiveSize {    
	// sizes in bytes
    private static final int INT_SIZE      = 4;
    private static final int SHORT_SIZE    = 2;
    private static final int LONG_SIZE     = 8;
    private static final int DOUBLE_SIZE   = 8;
    private static final int FLOAT_SIZE    = 4;
    
    private static final int CHAR_SIZE     = 2;
    private static final int BYTE_SIZE     = 1;
    private static final int BOOLEAN_SIZE  = 1;

    //private static final int OBJECT_SIZE   = 8;
    //private static final int OBJREF_SIZE   = 4;
    
    public static int sizeOf(int theInt) {
    	return INT_SIZE;
    }    
    public static int sizeOf(short theShort) {
    	return SHORT_SIZE;
    }    
    public static int sizeOf(long theLong) {
    	return LONG_SIZE;
    }     
    public static int sizeOf(double theDouble) {
    	return DOUBLE_SIZE;
    }   
    public static int sizeOf(float theFloat) {
    	return FLOAT_SIZE;
    }   
    public static int sizeOf(char theChar) {
    	return CHAR_SIZE;
    }   
    public static int sizeOf(byte theByte) {
    	return BYTE_SIZE;
    }   
    public static int sizeOf(boolean theBoolean) {
    	return BOOLEAN_SIZE;
    }  
    public static int sizeOf(JavaPrimitiveType type) throws RuntimeException {
    	switch(type) {
	    	case INTEGER:
	    		return INT_SIZE;
	    	case SHORT:
	    		return SHORT_SIZE;
	    	case LONG:
	    		return LONG_SIZE;
	    	case DOUBLE:
	    		return DOUBLE_SIZE;
	    	case FLOAT:
	    		return FLOAT_SIZE;
	    	case CHAR:
	    		return CHAR_SIZE;
	    	case BYTE:
	    		return BYTE_SIZE;
	    	case BOOLEAN:
	    		return BOOLEAN_SIZE;
    		default:
    			throw new RuntimeException("Invalid primitive type given: [" + type + "]");
    	}
    }    
    public static int sizeOf(String theString) {
    	int length = theString.length();
    	return length * CHAR_SIZE;
    }

}
